package com.ftg.learn.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 守卫拦截器
 * 数据接口拦截器类
 *    用来处理api接口请时对应的验证功能
 *       如是否正常登陆，是否存在token 判断令牌操作等功能
 * @author 布衣
 */
@Slf4j
public class ApiInterceptor implements HandlerInterceptor {

    public static final String TOKEN = "token";

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        log.info("请求地址- post：{}", request.getRequestURI());
    }

    @Override
    public boolean preHandle(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Object handler) throws Exception {
        log.info("请求地址 - pre：{}", request.getRequestURI());
        return true;
    }

    @Override
    public void afterCompletion(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Object handler, Exception ex) throws Exception {
        log.info(
                "请求地址 - after：{}，请求方法：{}，请求参数：{}，响应结果：{}",
                request.getRequestURI(),
                request.getMethod(),
                request.getQueryString(),
                response.getStatus()
        );
    }


}
